package wechat.rcv.mock.service;

import java.util.Collection;

import org.eclipse.xtext.xbase.lib.InputOutput;
import org.springframework.stereotype.Service;

import edu.fudan.langlab.domain.security.User;
import edu.fudan.langlab.security.shared.IFunctionIdentifier;
import edu.fudan.langlab.uidl.domain.app.server.service.login.ISecurityService;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IGenericQuery;
//import com.lanmon.workflow.security.SecurityService;

@Service("wechat.rcv.login.service.security.SecurityService")
public class SecurityServiceLMImpl extends BaseService implements ISecurityService {
  public User login(final String userid, final String passwd) {
    User _xblockexpression = null;
    {
      String _plus = (userid + ",");
      String _plus_1 = (_plus + passwd);
      InputOutput.<String>println(_plus_1);
      IGenericQuery<User> query=getObjectFactory().createGenericQuery(User.class,"select user from edu.fudan.langlab.domain.security.impl.UserImpl as user   where (((user.userid = :userid) and (user.passwd = :passwd)) and (user.locked = false)) and  user.active = 1      ").setParameter("userid",userid).setParameter("passwd",passwd);
      User _uniqueResult = query.uniqueResult();
      _xblockexpression = (_uniqueResult);
    }
    return _xblockexpression;
  }
  
//  public Iterable<LMRole> allRoles() {IGenericQuery<LMRole> query=getObjectFactory().createGenericQuery(LMRole.class,"select r from com.lanmon.workflow.security.impl.LMRoleImpl as r   where  r.active = 1      ");
//    Collection<LMRole> _list = query.list();
//    return _list;
//  }
//  
//  public Iterable<LMRole> findRolesByUser(final User user) {
//    return null;
//  }
  
  public Iterable<User> allUser() {IGenericQuery<User> query=getObjectFactory().createGenericQuery(User.class,"select u from edu.fudan.langlab.domain.security.impl.UserImpl as u   where  u.active = 1      ");
    Collection<User> _list = query.list();
    return _list;
  }
  
  public User findUserByUserId(final String userid) {
    IGenericQuery<User> query=getObjectFactory().createGenericQuery(User.class,"select user from edu.fudan.langlab.domain.security.impl.UserImpl as user   where (user.userid = :userid) and  user.active = 1      ").setParameter("userid",userid);
    User _uniqueResult = query.uniqueResult();
    return _uniqueResult;
  }
  
//  public Iterable<LMFunction> findFunctionsByUser(final User user) {
//    HashSet<LMFunction> _xblockexpression = null;
//    {
//      HashSet<LMFunction> _hashSet = new HashSet<LMFunction>();
//      final HashSet<LMFunction> result = _hashSet;
//      _xblockexpression = (result);
//    }
//    return _xblockexpression;
//  }
//  
//  public LMFunction findFunctionByFunctionId(final String fid) {
//    IGenericQuery<LMFunction> query=getObjectFactory().createGenericQuery(LMFunction.class,"select function from com.lanmon.workflow.security.impl.LMFunctionImpl as function   where (function.functionId = :fid) and  function.active = 1      ").setParameter("fid",fid);
//    Collection<LMFunction> _list = query.list();
//    LMFunction _head = IterableExtensions.<LMFunction>head(_list);
//    return _head;
//  }
//  
//  public LMRole findRoleByRoleId(final String rid) {
//    IGenericQuery<LMRole> query=getObjectFactory().createGenericQuery(LMRole.class,"select role from com.lanmon.workflow.security.impl.LMRoleImpl as role   where (role.roleId = :rid) and  role.active = 1      ").setParameter("rid",rid);
//    LMRole _uniqueResult = query.uniqueResult();
//    return _uniqueResult;
//  }
  
  public void resetPassword(final User user) {
    String _userid = user.getUserid();
    user.setPasswd(_userid);
  }

@Override
public Collection<? extends IFunctionIdentifier> loadValidFunctions4User(String userid) {
	// TODO Auto-generated method stub
	return null;
}
}
